﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using SlimDX.Direct2D;
using System.Drawing;

namespace GaugeEngine.Graphics
{
    public class Painter
    {
        private RenderTarget m_renderTarget;
        private Dictionary<string, SolidColorBrush> m_brushes;

        public void setRenderTarget(RenderTarget rt)
        {
            m_renderTarget = rt;
        }

        public Painter(RenderTarget renderTarget)
        {
            m_renderTarget = renderTarget;
            m_brushes = new Dictionary<string, SolidColorBrush>();
        }

        public void DrawPoint(Vector point)
        {
            
        }

        public void Clear(System.Drawing.Color col)
        {
            m_renderTarget.Clear(col);
        }

        public void DrawLine(Vector p1, Vector p2, Color col)
        {
            SolidColorBrush scb;
            if (m_brushes.ContainsKey(col.ToString())) scb = m_brushes[col.ToString()];
            else
            {
                scb = new SolidColorBrush(m_renderTarget, col);
                m_brushes.Add(col.ToString(), scb);
            }
            m_renderTarget.DrawLine( scb, new PointF(p1.X, p1.Y), new PointF(p2.X, p2.Y));
        }

        public void DrawSprite(Vector position, Sprite spr)
        {
            SlimDX.Direct2D.Bitmap bitmap = GraphicsManager.LoadBitmap(m_renderTarget, spr.Image);
            m_renderTarget.DrawBitmap(bitmap, new RectangleF(position.X, position.Y, spr.Image.Width, spr.Image.Height));
            bitmap.Dispose();
        }

        public void Dispose()
        {
            foreach (SlimDX.Direct2D.Brush brush in m_brushes.Values)
            {
                brush.Dispose();
            }
        }
    }
}
